var projectAdvancedSearch = {
	getData : function() {
		var f_id = $("#fcCategoryId").attr("fcCategoryId");
		var s_id = $("#scCategoryId").attr("scCategoryId");
		var t_id = $("#tcCategoryId").attr("tcCategoryId");

		var name = $("#projectName").val();
		// var submitSide = $("#submitSide").val();
		// var fundPlan = $("#fundPlan").val();
		var mgrDepart = $("#mgrDepart").val();
		// var leadDepart = $("#leadDepart").val();
		// var dutySide = $("#dutySide").val();
		var buildSide = $("#buildSide").val();
		var plan = $("[name='plan']:checked").val();
		var checkout = $("[name='checkout']:checked").val();
		// var history = $("[name='history']:checked").val();
		var area = "";
		$("[name='area']:checked").each(function(i) {
			var v = $(this).val();
			if (v != null && 0 != v.length) {
				switch (i) {
				case 0:
					area += v;
					break;
				default:
					area += "," + v;
					break;
				}
			}
		});
		var ispass = $("[name='ispass']:checked").val();

		var startTime = $("#startTime").val();
		var endTime = $("#endTime").val();
		var startFund = $("#startFund").val();
		var endFund = $("#endFund").val();
		checkTime(startTime, endTime);
		checkFund(startFund, endFund);
		startTime = $("#startTime").val();
		endTime = $("#endTime").val();
		startFund = $("#startFund").val();
		endFund = $("#endFund").val();
		if (null != startFund && 0 != startFund.length && "" != startFund && isNaN(startFund)) {
			errorAlert("请正确填写起始总投资数目！");
			return false;
		}
		if (null != endFund && 0 != endFund.length && "" != endFund && isNaN(endFund)) {
			errorAlert("请正确填写截止总投资数目！");
			return false;
		}
		var comment = $("[name='comment']:checked").val();
		_projectAdvancedSearchGetData = $("#pageShow").myPagination({
			currPage : 1,
			pageCount : 10,
			pageNumber : 5,
			panel : {
				tipInfo_on : true,
				links : "javascript:void()"
			},
			ajax : {
				onClick : function(page) {
					ZENG.msgbox.show(" 正在加载" + page + "页，请稍后...", 6, 600);
					nowPage = page;
				},
				on : true,
				type : "POST",
				dataType : 'json',
				url : "/app/project!getProjectAdvancedSearch",
				param : {
					"f_id" : f_id,
					"s_id" : s_id,
					"t_id" : t_id,
					"projectName" : name,
					"startTime" : startTime,
					"endTime" : endTime,
					"startFund" : startFund,
					"endFund" : endFund,
					// "submitSide" : submitSide,
					// "fundPlan" : fundPlan,
					"mgrDepart" : mgrDepart,
					// "leadDepart" : leadDepart,
					// "dutySide" : dutySide,
					"buildSide" : buildSide,
					"plan" : plan,
					"area" : area,
					"ispass" : ispass,
					"checkout" : checkout,
					// "history" : history,
					"comment" : comment
				},
				callback : function(data) {
					backUrl.addCookie(data.state);
					if ('success' == data.state) {
						pageCountId = data.pageCount;// 获取总页数
						projectAdvancedSearch.createContent(data.msg);
					} else if (data.state == "error") {
						errorAlert(data.msg);
					}
				}
			}
		});
	},
	createContent : function(data) {
		var dc = $("#dataContent");
		dc.empty();
		var content = "";
		if (data != null && data.length != 0) {
			$("#pageShow").show();
			content = "<tr id='titleTr'><th width='30%' scope='col'>项目名称</th><th width='10%' scope='col'>实施时间</th>"
					+ "<th width='10%' scope='col'>总投资（亿）</th><th width='15%' scope='col'>主管部门</th><th width='20%' scope='col'>资金来源</th>"
					+ "<th width='10%' scope='col'>批示</th><th width='5%' scope='col'>操作</th></tr>";
			for ( var int = 0; int < data.length; int++) {
				var v = data[int];
				var id = v.id;
				var name = v.name;
				var fund = v.fund;
				var impl = v.impl_time;
				var fundPlan = v.fund_plan;
				var mgrDepart = v.mgr_depart;
				var comment = v.comment;
				var checkout = v.checkout;

				var _name = name;
				if (name.length > 26) {
					name = name.substring(0, 24) + "...";
				}
				var _fundPlan = fundPlan;
				if (fundPlan.length > 17) {
					fundPlan = fundPlan.substring(0, 16) + "...";
				}
				var _mgrDepart = mgrDepart;
				if (mgrDepart.length > 13) {
					mgrDepart = mgrDepart.substring(0, 11) + "...";
				}
				var _comment = "";
				if (Number(comment) == 2) {
					_comment = "<img src='/img/comment.png'>";
				}
				if (Number(checkout) == 1) {
					content += "<tr class='checkout'>";
				} else {
					content += "<tr>";
				}
				content += "<td align='center'><a href='/app/project!getProjectDetailedById?p_id=" + id
						+ "' target='_blank' title='" + _name + "' class='tempClass'>" + name
						+ "</a></td><td align='center'>" + impl + "</td><td align='center'>" + fund
						+ "</td><td align='center' title='" + _mgrDepart + "'>" + mgrDepart
						+ "</td><td align='center' title='" + _fundPlan + "'>" + fundPlan
						+ "</td><td align='center'><font color='red'>" + _comment
						+ "</font></td><td align='center'><a href='javascript:projectNotation.show(" + id
						+ ")'>批示</a></td></tr>";
			}
		} else {
			$("#pageShow").hide();
			content = "<tr id='noData'><td align='center'><h1>暂无数据</h1></td></tr>";
		}
		dc.append(content);
		projectAdvancedSearchPoshytip();
	},
	jumpPage : function() {// 分页跳转
		_projectAdvancedSearchGetData.jumpPage(nowPage);
	}
};
function projectAdvancedSearchPoshytip() {
	$("#dataContent").find("td").poshytip({
		className : 'tip-darkgray',
		showOn : 'hover',
		alignTo : 'target',
		alignX : 'center',
		alignY : "center",
		allowTipHover : true,
		fade : true,
		slide : true
	});
	$(".tempClass").poshytip({
		className : 'tip-darkgray',
		showOn : 'hover',
		alignTo : 'target',
		alignX : 'right',
		alignY : "center",
		offsetX : 10,
		allowTipHover : true,
		fade : true,
		slide : true
	});
};
/**
 * 检查时间
 * 
 * @param st
 * @param ed
 * @return
 */
function checkTime(st, ed) {
	if (null != st && null != ed && 0 < st.length && 0 < ed.length) {
		var time;
		if (ed < st) {
			time = st;
			st = ed;
			ed = time;
			$("#startTime").val(st);
			$("#endTime").val(ed);
		}
	}
}
/**
 * 检查投资
 * 
 * @param st
 * @param ed
 * @return
 */
function checkFund(st, ed) {
	if (null != st && null != ed && 0 < st.length && 0 < ed.length) {
		var time;
		if (ed < st) {
			time = st;
			st = ed;
			ed = time;
			$("#startFund").val(st);
			$("#endFund").val(ed);
		}
	}
}
/**
 * 重置
 */
function resetAdvancedSearch() {
	// $("#fcCategoryId").click();
	// $("#scCategoryId").click();
	$("#tcCategoryId").click();
	$("#projectName").val("");
	$("#startTime").val("");
	$("#endTime").val("");
	$("#startFund").val("");
	$("#endFund").val("");
	// $("#submitSide").val("");
	// $("#fundPlan").val("");
	$("#mgrDepart").val("");
	// $("#leadDepart").val("");
	// $("#dutySide").val("");
	$("#buildSide").val("");
	$("[name='plan']").eq(0).prop('checked', true);

	$("[name='area']").removeAttr("checked");
	$("[name='area']").eq(0).prop('checked', true);

	$("[name='ispass']").eq(0).prop('checked', true);
	$("[name='checkout']").eq(0).prop('checked', true);
	$("[name='comment']").eq(0).prop('checked', true);
	projectAdvancedSearch.getData();
}
/**
 * 批示后跳转的方法
 */
function projectNotationJump() {
	projectAdvancedSearch.jumpPage();
}
var onloadProjectAdvancedSearch = {
	onload : function() {
		projectAdvancedSearch.getData();
		$("#serach").click(function() {
			projectAdvancedSearch.getData();
		});
		$("#reset").click(function() {
			resetAdvancedSearch();
		});
		$("#serachAll").click(function() {
			resetAdvancedSearch();
			projectAdvancedSearch.getData();
		});
		$("#areaAll").click(function() {
			$("[name='area']:checked").each(function() {
				var v = $(this).attr("id");
				if (v != "areaAll") {
					$(this).removeAttr("checked");
				}
			});
		});
		$("[name='area']").click(function() {
			var v = $(this).attr("id");
			if (v != "areaAll") {
				$("#areaAll").removeAttr("checked");
			}
		});
		$("#startTime").focus(function() {
			WdatePicker({
				dateFmt : 'yyyy-MM'
			});
		});
		$("#endTime").focus(function() {
			WdatePicker({
				dateFmt : 'yyyy-MM'
			});
		});
		$("[name='plan']").click(function() {
			projectAdvancedSearch.getData();
		});
		$("[name='comment']").click(function() {
			projectAdvancedSearch.getData();
		});
		$("[name='checkout']").click(function() {
			projectAdvancedSearch.getData();
		});
		$("[name='ispass']").click(function() {
			projectAdvancedSearch.getData();
		});
	}
};